package com.gujianjian.rabbitmq.config;

import cn.hutool.json.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 去掉过期队列的测试
 */
@Component
@Slf4j
public class RabbitmqConfig2 {

    @Bean("queue2")
    public Queue queue2(){
        return QueueBuilder.durable("queue2")
                .withArgument("x-dead-letter-exchange","exchange.dlx1")
                .withArgument("x-dead-letter-routing-key","key.dlx1") // key.dlx.car.rent.#
                // .withArgument("x-message-ttl",1000 * 10)
                .build();
    }

    @Bean("exchange2")
    public Exchange exchange2(){
        return ExchangeBuilder.directExchange("exchange2").build();
    }
    @Bean
    public Binding binding2(@Qualifier("queue2")Queue queue2,@Qualifier("exchange2")Exchange exchange1){
        // 这里的交换机exchange1 ，在RabbitmqConfig中已经创建了，这里就不创建了
        return BindingBuilder.bind(queue2).to(exchange1).with("key.queue2").noargs();
    }


}
